<template>
    <!-- 供应商年度评价-新增 -->
    <div class="e-form">
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <div style="width: 100%" class="form">
                <el-form :model="formData" label-width="150px">
                    <BillTop title="供应商年度评价新增" @cancel="handleClose"></BillTop>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="合同名称">
                                <el-input
                                    v-model="formData.contractName"
                                    disabled
                                >
                                    <i
                                        slot="suffix"
                                        class="el-icon-document-copy"
                                        @click="onContract"
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="合同类型">
                                {{ formData.contractType }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="统一社会信用代码">
                                {{ formData.creditCode }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商名称">
                                {{ formData.supplierName }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="供应商类型">
                                {{ formData.supplierTypeKey }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商品/资质等级">
                                {{ formData.qualificationLevelName }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="历史信用等级">
                                <span>
                                    {{
                                        formData.creditLevel == '0'
                                            ? '待定'
                                            : formData.creditLevel == '1'
                                            ? 'A'
                                            : formData.creditLevel == '2'
                                            ? 'B'
                                            : formData.creditLevel == '3'
                                            ? 'C'
                                            : formData.creditLevel == '4'
                                            ? 'D'
                                            : formData.creditLevel == '5'
                                            ? 'S'
                                            : ''
                                    }}</span
                                >
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="评价机构">
                                {{ formData.evaluateOrg }}</el-form-item
                            >
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="评价日期：">
                                {{ formData.evaluateDate }}
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="上级机构"
                                >{{ formData.superiorOrg }}
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="状态:">
                                {{ formData.evaluateQuarter }}</el-form-item
                            >
                        </el-col>
                    </el-row>
                </el-form>
            </div>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                style="background: #2e61d7"
                @click="save()"
                >保存</el-button
            >
            <el-button @click="cancel()">取消</el-button>
        </div>
    </div>
</template>

<script>
import { selectDataClient, showSuccessPop } from '@/utils/common'
import subcontractorRAP from '@/api/OutsourcingartyAdmin/subcontractorAdmin/subcontractorRAP.js'
export default {
    data () {
        return {
            //表单数据
            formData: {
                contractName: '', //合同名称
                supplierName: '', //供应商名称
                contractType: '', //合同类型
                creditCode: '', //统一社会信用代码
                supplierType: '', //供应商类型
                supplierCommodity: '', //供应商品/资质等级
                credit: '', //历史信用等级
                evaluateConclusion: '', //当前评价结论
                evaluateDate: '', //评价日期：
                evaluateQuarter: '', //评价季度
                evaluateOrg: '', //评价机构
                superiorOrg: '' //上级机构
            },

            //类型列表
            typeList: [],
            //奖惩类型列表
            rewardsOrPunishment: [],
            orgId: '', //机构id
            orgName: '', //机构名称
            time: '', //当前时间
            kvKey: '', //外包方名称
            kvValue: '' //外包方值
        }
    },
    created () {
        let data = JSON.parse(localStorage.getItem('vuex'))
        this.orgId = data.userInfo.orgInfo.orgId
        this.orgName = data.userInfo.orgInfo.orgName
        this.formData.evaluateOrg = this.orgName
        this.formData.superiorOrg = this.orgName
    },
    methods: {
        // 合同名称查询
        onContract () {
            // 弹窗选择数据
            selectDataClient({
                SelectServiceToken:
                    '/outer/year/evaluate/sup/get/contract', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                InitParamsStr: '',
                Title: '合同选择'
            }).then(val => {
                //选择的合同赋值
                this.formData = val[0]
            })
        },
        //日期转换格式
        getTime (dt) {
            var year = dt.getFullYear() //年
            var month = dt.getMonth() + 1 //月
            var date = dt.getDate() //日
            month = month < 10 ? '0' + month : month
            date = date < 10 ? '0' + date : date
            var str = year + '-' + month + '-' + date
            return str
        },
        //保存按钮
        async save () {
            let data = JSON.parse(JSON.stringify(this.formData))
            let datas = await subcontractorRAP.annualEvaluationAdd(data)
            if (datas.code != 200) {
                this.clientPop(
                    'info',
                    '保存成功！是否进行下一步操作？',
                    this.gocallback(datas),
                    null,
                    this.cancelCallBack(datas)
                ) // 如果没有参数，且没有 取消 回调事件，则不用传后面两个参数
            } else {
                showSuccessPop('保存失败')
            }
        },
        // 保存成功继续回调
        gocallback (billid) {
            return () => {
                this.$router.push({
                    path: '/dynamicEvaluateEdit',
                    query: { billid }
                })
            }
        },
        // 保存成功，取消回调
        cancelCallBack (billid) {
            return () => {
                this.$router.push({
                    path: '/dynamicEvaluate',
                    query: { billid }
                })
            }
        },
        //取消按钮
        cancel () {
            this.$router.push('/dynamicEvaluate')
        },
        //获取当前时间
        getDate () {
            var date = new Date()
            var y = date.getFullYear()
            var m = date.getMonth() + 1
            var d = date.getDate()
            this.time = `${y}-${m}-${d}`
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    margin-bottom: 80px;
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}

.form {
}

.e-table {
    background: #fff;
}

.el-tab-pane {
    margin-left: -10px;
}
</style>
